package logic

import (
	"context"
	"house_srv/houseclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddImgLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddImgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddImgLogic {
	return &AddImgLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddImgLogic) AddImg(req *types.AddImgRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.HouseRpc.AddImg(l.ctx, &houseclient.AddImgRequest{
		HouseId: int64(req.HouseId),
		Url:     req.Url,
		Name:    req.Name,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    sms,
	}, nil
}
